package com.spotalog.shared.model;

import java.util.Date;

import lombok.Data;
import lombok.EqualsAndHashCode;

import com.googlecode.objectify.annotation.Id;
import com.googlecode.objectify.annotation.OnSave;

@Data
@EqualsAndHashCode(of = { "id" })
public class DatastoreObject {
	@Id
	private Long id;
	private Integer version = 0;
	private Date dateAltered;
	private Date dateCreated;

	/**
	 * Auto-increment version # whenever persisted
	 */
	@OnSave
	void onPersist() {
		if (this.version != null) {
			this.version++;
		} else {
			this.version = 0;
		}
		setDateAltered(new Date());
	}

	public static final String ID = "id";
	public static final String VERSION = "version";
	public static final String DATE_ALTERED = "dateAlerted";
	public static final String DATE_CREATED = "dateCreated";
}